import { defineNuxtRouteMiddleware } from "nuxt/app";

let paddingGapRoute = ["/job/detail",'/aviation/detail'];

function SetBodyPadding(to) {
  if (paddingGapRoute.includes(to.path)) {
    if (document?.body?.clientWidth <= 768) {
      document.body.classList.add("gap-bottom");
    } else {
      if (document?.body.classList.contains("gap-bottom")) {
        document?.body.classList.remove("gap-bottom");
      }
    }
  } else {
    if (document?.body.classList.contains("gap-bottom")) {
      document?.body.classList.remove("gap-bottom");
    }
  }
}

function resetRoute(to) {
  if (to.path.includes("mobile")) {
    if (!isMobile()) {
      goto("/");
    }
  }
}

export default defineNuxtRouteMiddleware((to, from) => {
  window?.scrollTo({
    top: 0,
  });
  SetBodyPadding(to);
  window?.addEventListener("resize", () => {
    SetBodyPadding(to);
    // resetRoute(to)
  });
});
